<template>
  <div class="detail-logistics" v-if="list">
    <p>
      <span>{{ list[0].time }}</span>
      <span>{{ list[0].text }}</span>
    </p>
    <a href="javascript:;" @click="orderLogistics(order)">查看物流</a>
  </div>
  <order-logistics ref="logisticsTarget"></order-logistics>
</template>
<script>
import { ref } from "vue";
import { logisticsOrder } from "api/order";
import OrderLogistics from "./OrderLogistics.vue";
import { useLogistics } from "../Index.vue";
export default {
  components: { OrderLogistics },
  name: "DetailLogistics",
  props: {
    order: {
      type: Object,
      default: () => ({}),
    },
  },
  //setup在create和其之前执行，不能async异步，组件无法初始化
  //这里可以使用官网给的Suspense组件包裹再async
  // async setup(props) {
  //   const data = await logisticsOrder(props.order.id);
  //   const list = ref(data.result.list);
  //   console.log(list.value);
  //   return { list };
  // },

  setup(props) {
    const list = ref(null);
    logisticsOrder(props.order.id).then((data) => {
      list.value = data.result.list;
    });

    return { list, ...useLogistics()  };
  },
};
</script>
<style scoped lang="less">
.detail-logistics {
  height: 50px;
  display: flex;
  align-items: center;
  padding: 0 30px;
  background-color: #f5f5f5;
  margin: 30px 50px 0;
  > p {
    flex: 1;
    span {
      color: #999;
      &:first-child {
        margin-right: 30px;
      }
    }
  }
  > a {
    color: @xtxColor;
    text-align: center;
  }
}
</style>
